import os
import sys
import shutil
from pathlib import Path

# 导入migrate_data函数
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from migrate_data import migrate_data

class ConfigManager:
    """配置管理类，用于管理数据库和日志文件的路径"""
    
    _instance = None
    
    def __new__(cls):
        if cls._instance is None:
            cls._instance = super(ConfigManager, cls).__new__(cls)
            cls._instance._initialize()
        return cls._instance
    
    def _initialize(self):
        """初始化配置"""
        # 确定应用根目录
        if getattr(sys, 'frozen', False):
            # 打包后的应用
            self.app_root = os.path.dirname(sys.executable)
        else:
            # 开发环境
            self.app_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        
        # 调用migrate_data函数迁移数据并获取新路径
        paths = migrate_data()
        self.db_path = paths["db_path"]
        self.log_file = paths["log_file"]
    
    def get_db_path(self):
        """获取数据库路径"""
        return self.db_path
    
    def get_log_file(self):
        """获取日志文件路径"""
        return self.log_file

# 创建全局实例
config = ConfigManager()